package com.cqc.checkedtextview01;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.checked_tv)
    CheckedTextView checkedTv;
    @BindView(R.id.btn)
    Button btn;
    @BindView(R.id.checked_tv2)
    CheckedTextView checkedTv2;
    private Toast toast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
        ButterKnife.bind(this);

        checkedTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                checkedTv.toggle();
            }
        });

        checkedTv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                checkedTv2.toggle();
            }
        });
    }

    @OnClick(R.id.btn)
    public void onClick() {
        toast.setText("状态是：" + checkedTv.isChecked());
        toast.show();
    }

}
